import { computed } from 'vue'
import store from '@/store'

const getters = store.getters

/*********************身份大类**********************/
export const isAbpIdentity = computed(() => { return hasSpecialRole("AbpIdentity") })
// 角色管理
export const isRolesManage = computed(() => { return hasSpecialRole("AbpIdentity.Roles") })
// 创建角色
export const isRolesCreate = computed(() => { return hasSpecialRole("AbpIdentity.Roles.Create") })
// 修改角色
export const isRolesUpdate = computed(() => { return hasSpecialRole("AbpIdentity.Roles.Update") })
// 删除角色
export const isRolesDelete = computed(() => { return hasSpecialRole("AbpIdentity.Roles.Delete") })
// 权限管理
export const isRolesPermissions = computed(() => { return hasSpecialRole("AbpIdentity.Roles.ManagePermissions") })
// 用户管理
export const isUsersManage = computed(() => { return hasSpecialRole("AbpIdentity.Users") })
// 创建用户
export const isUsersCreate = computed(() => { return hasSpecialRole("AbpIdentity.Users.Create") })
// 修改用户
export const isUsersUpdate = computed(() => { return hasSpecialRole("AbpIdentity.Users.Update") })
// 删除用户
export const isUsersDelete = computed(() => { return hasSpecialRole("AbpIdentity.Users.Delete") })
// 用户权限
export const isUsersPermissions = computed(() => { return hasSpecialRole("AbpIdentity.Users.ManagePermissions") })

/*********************系统管理**********************/
export const isSystemSettings = computed(() => { return hasSpecialRole("SystemManagement.SystemSettings") })
export const isSystemSettingsUpdate = computed(() => { return hasSpecialRole("SystemManagement.SystemSettings.Update") })
export const isLogManage = computed(() => { return hasSpecialRole("SystemManagement.Log") })
export const isLogAuditLog = computed(() => { return hasSpecialRole("SystemManagement.Log.AuditLog") })
export const isLogSecurityLog = computed(() => { return hasSpecialRole("SystemManagement.Log.SecurityLog") })

export function isHasPermission(roleName) {
    let index = getters.roles.findIndex(role => {
        role = role.replace(".", "")
        roleName = roleName.replace(".", "")
        return role == roleName
    })
    return index != -1
}

export function hasSpecialRole(role) {
    return getters.roles.indexOf(role) != -1
}